/**
 * Created by wanghuan on 2017/4/9.
 */

/*==========================timeReport 相关接口==============================*/

import Ajax from '../../apiAjax';

export  default {
  state:{
    timeReportPeriod:{},//time Report 选择日期，
    timeReportList:[],//列表,
    timeReportDetailInfo:{},
    timeReportDetailList:[]
  },
  mutations:{
    setCommonStateData(state,{key,data}){
      state[key] = data;
    }
  },
  actions:{
    /**
     *查询time Report init
     * @param commit
     * @param paramData = {}
     * @returns {Promise}
     */
    getTimeReportPeriod({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/report/initperiod',
          data:paramData,
          success:function (data) {
            commit('setCommonStateData',{key:'timeReportPeriod',data:data.data});
            resolve(data);
          }
        })
      })
    },
    /**
     *
     * @param commit
     * @param paramData ={
     * startDate	String 开始时间，格式：yyyy-MM-dd
      endDate	String 结束，格式：yyyy-MM-dd
      approveStatus	int 0:unapproved，1:approved，2:all（不传默认为0）
      }
     * @returns {Promise}
     */
    getTimeReportList({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/report/list',
          data:paramData,
          success:function (data) {
            commit('setCommonStateData',{key:'timeReportList',data:data.data});
            resolve(data);
          }
        })
      })
    },
    /**
     * 通过审核
     * @param commit
     * @param paramData
     * employeeIds	String	是	以','分割的员工ID字符串
       approveDate	String	是	审核时间，格式'yyyy-MM-dd'
     * @returns {Promise}
     */
    approveTimeReport({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/report/approve',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    /**
     * 取消审核
     * @param commit
     * @param paramData
     *  employeeIds	String	是	以','分割的员工ID字符串
        unapproveDate	String	是	取消审核时间，格式'yyyy-MM-dd'
     * @returns {Promise}
     */
    unApproveTimeReport({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/report/unapprove',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    /**
     *
     * @param commit
     * @param paramData
     * {employeeId,beginDate,endDate}
     * @returns {Promise}
     */
    getTimeReportDetailInfo({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/report/detail/overview',
          data:paramData,
          success:function (data) {
            commit('setCommonStateData',{key:'timeReportDetailInfo',data:data.data});
            resolve(data);
          }
        })
      })
    },
    getTimeReportDetailList({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/report/detail/list',
          data:paramData,
          success:function (data) {
            commit('setCommonStateData',{key:'timeReportDetailList',data:data.data});
            resolve(data);
          }
        })
      })
    }
  },
  getters: {
    timeReportPeriod:(state, getters)=> {
      return state.timeReportPeriod;
    },
    timeReportList:(state, getters)=> {
      return state.timeReportList;
    },
    timeReportDetailInfo:(state, getters)=> {
      return state.timeReportDetailInfo;
    },
    timeReportDetailList:(state, getters)=> {
      return state.timeReportDetailList;
    },

  }
}
